package com.jacky.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: jacky
 * @date: 2018/6/4
 * Time: 11:13
 * Description:
 **/
public class JdkDynamicProxy {
   public BookApi createJdkDynamicProxy() {
        BookApi jdkProxy = (BookApi) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),
                new Class[]{BookApi.class}, new JdkHandler());
        return jdkProxy;
    }

    public class JdkHandler implements InvocationHandler {
        @Override
        public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
            //添加代理逻辑<1>
            if (method.getName().equals("sell")) {
                System.out.print("");
            }
            return null;
            //return method.invoke(delegate, objects);
        }
    }

}
